package com.lp.compt.controllers;

import org.springframework.web.bind.annotation.*;
import org.springframework.http.ResponseEntity;
import org.springframework.data.domain.Pageable;
import org.springframework.beans.factory.annotation.Autowired;
import com.lp.compt.pojo.SsResultsEntity;
import com.lp.compt.services.SsResultsEntityService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 服务类
 *
 * @author
 * @since 1.0.0
 */
@RestController
@CrossOrigin
@RequestMapping("/ssResultsEntity")
public class SsResultsEntityController {

    final
    SsResultsEntityService ssResultsEntityService;

    public SsResultsEntityController(SsResultsEntityService ssResultsEntityService) {
        this.ssResultsEntityService = ssResultsEntityService;
    }

    /**
     * 根据SsResultsEntity的字段,自动生成条件,字段的值为null不生成条件
     * http://localhost:8080/user/?id=1
     *
     * @param ssResultsEntity 实体对象
     * @param pageable        分页/排序对象
     * @return 返回的是实体, 里面涵盖分页信息及状态码
     */
    @GetMapping
    ResponseEntity<Object> search(SsResultsEntity ssResultsEntity, Pageable pageable) {
        return ssResultsEntityService.search(ssResultsEntity, pageable);
    }

    @GetMapping("where")
    List<SsResultsEntity> searchByWhere(SsResultsEntity ssResultsEntity) {
        return ssResultsEntityService.searchByWhere(ssResultsEntity);
    }

    @PostMapping
    Map create(@RequestBody SsResultsEntity entity) {
        return ssResultsEntityService.save(entity);
    }

    @PostMapping("upr")
    Map update(@RequestBody Map<String, Integer> map, Integer id, Integer up, Integer userid) {
        ssResultsEntityService.up(map);
        return new HashMap() {{
            put("code", 200);
            put("msg", "添加成功");
        }};
    }

    @PostMapping("queryUser")
    Object queryUser(@RequestBody Map<String, Integer> map) {
        return ssResultsEntityService.queryUser(String.valueOf(map.get("id")));
    }

    @DeleteMapping("/")
    void delete() {
    }
}
